package com.lzk.controller;

import com.lzk.domain.ResponseResult;
import com.lzk.domain.dto.ChangeRoleStatusDto;
import com.lzk.domain.entity.Role;
import com.lzk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author: 刘中魁
 */
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    public RoleService roleService;

    @GetMapping("/list")
    private ResponseResult getRoleList(Role role,Integer pageNum,Integer pageSize){
        return roleService.getRoleList(role,pageNum,pageSize);
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody ChangeRoleStatusDto roleStatusDto){
        Role role = new Role();
        role.setId(roleStatusDto.getRoleId());
        role.setStatus(roleStatusDto.getStatus());
        return ResponseResult.okResult(roleService.updateById(role));
    }

    //---------新增---------------
    @PostMapping
    public ResponseResult add( @RequestBody Role role) {
        roleService.insertRole(role);
        return ResponseResult.okResult();

    }

    @GetMapping("/{id}")
    public ResponseResult getRoleMes(@PathVariable Integer id){
        return roleService.getRoleMes(id);
    }

    //-----------修改-----------------
    @PutMapping
    public ResponseResult edit(@RequestBody Role role) {
        roleService.updateRole(role);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delectRole(@PathVariable Long id){
        this.roleService.removeById(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/listAllRole")
    public ResponseResult listAllRole(){
        List<Role> roles = roleService.listAllRole();
        return ResponseResult.okResult(roles);
    }



}
